package com.sk.restree.model.dao;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.sk.restree.model.dto.CardDTO;
import com.sk.restree.model.dto.MemberDTO;
import com.sk.restree.model.ibatis.SqlMapFactory;

public class CardDAO {
	private static CardDAO cardDAO;
	SqlMapClient sqlMap;
	
	static {
		cardDAO = new CardDAO();
	}

	private CardDAO() {
		sqlMap = SqlMapFactory.getSqlMapInstance();
	}

	public static CardDAO getInstance() {
		return cardDAO;
	}

	public MemberDTO modifycard(MemberDTO dto, String cname) {
		MemberDTO rdto = null;
		String member_id = dto.getMember_id();
		List<CardDTO> cardlist = BankListDAO.getIntance().selectCardAsBname(cname);
		String card_id = null;
		for(CardDTO card:cardlist){
			if(card.getCname().equals(cname)){
				card_id = card.getCard_id();
			}
		}
		Map<String, String> map = new HashMap<String, String>();
		map.put("member_id", member_id);
		map.put("card_id", card_id);
		try {
			sqlMap.update("modifycard", map);
			rdto = (MemberDTO) sqlMap.queryForObject("login",dto);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return rdto;
	}
	
//	public CardDAO(SqlMapClient sqlMapClient) {
//		this.sqlMapClient = sqlMapClient;
//	}
	
	//public List<CardDTO> selectCardList()
}
